﻿package core.ui.controls
{
    import core.event.*;
    import flash.display.*;

    public class CheckItem extends Sprite
    {
        public var cb:Checkbox;
        private var bg:Sprite;
        public var title:Literal;

        public function CheckItem(param1:String, param2:String)
        {
            this.name = param1;
            this.bg = new Sprite();
            this.bg.graphics.beginFill(11447982);
            this.bg.graphics.drawRect(0, 0, 130, 20);
            this.bg.graphics.endFill();
            this.bg.alpha = 0;
            addChild(this.bg);
            this.title = new Literal(param2);
            this.title.x = 18;
            this.title.y = 0;
            addChild(this.title);
            this.cb = new Checkbox();
            this.cb.x = 5;
            this.cb.y = 2;
            this.cb.addEventListener(ChangeEvent.CHANGE, this.CheckboxChange, false, 1, true);
            addChild(this.cb);
            return;
        }// end function

        public function Marking(core.event:Boolean) : void
        {
            if (core.event)
            {
                this.bg.alpha = 0.5;
                if (!this.cb.checked)
                {
                    this.cb.Check();
                    dispatchEvent(new ChangeEvent(true));
                }
            }
            else
            {
                this.bg.alpha = 0;
            }
            return;
        }// end function

        public function CheckboxChange(event:ChangeEvent) : void
        {
            dispatchEvent(new ChangeEvent(int(this.cb.checked)));
            return;
        }// end function

    }
}
